package com.xudow.app.newui;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.xudow.app.R;
import com.xudow.app.newui.base.BaseUiActivity;
import com.xudow.app.ui.LoginActivity;
import com.xudow.app.ui.RegisterActivity;

import butterknife.BindView;

public class PreLoginActivity extends BaseUiActivity {
    private boolean gohome=false;

    @BindView(R.id.img)
    ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pre_login);
        gohome=getIntent().getBooleanExtra("GOTOHOME",false);
        img.setAlpha(0.8f);


    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    public void goToLogin(View v){


        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        dialogBuilder.create();

        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.layout_login, null);
        dialogBuilder.setView(view);
        AlertDialog alertDialog=dialogBuilder.show();
        Button bt_ok=(Button)view.findViewById(R.id.bt_ok);
        Button bt_no=(Button)view.findViewById(R.id.bt_no);

        bt_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                Intent intent=new Intent(PreLoginActivity.this,LoginActivity.class);
                intent.putExtra("GOTOHOME",gohome);
                startActivity(intent);
                finish();

            }
        });
        bt_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                alertDialog.dismiss();
            }
        });
    }
    public void goTogRegist(View v){

        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
       dialogBuilder.create();

        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.layout_register, null);
        dialogBuilder.setView(view);
        AlertDialog alertDialog=dialogBuilder.show();
        Button bt_ok=(Button)view.findViewById(R.id.bt_ok);
        Button bt_no=(Button)view.findViewById(R.id.bt_no);

        bt_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
               startActivity(new Intent(PreLoginActivity.this, RegisterActivity.class));

            }
        });
        bt_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                alertDialog.dismiss();
            }
        });


    }

    public void goToAgencyListPage(View v) {
        startActivity(new Intent(this, AgencyListActivity.class));
        //finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (gohome) {//重退出登录界面转入 back键关闭application
            sendExitBroadcast();
        }
        return super.onKeyDown(keyCode, event);
    }
}
